package com.scalpel.web.util;

import com.alibaba.fastjson.JSONObject;
import sun.plugin.javascript.navig.JSObjectFactory;

/**
 * Created by scalpel on 2017/1/5.
 */
public class Ajax {


    /**
     * 成功
     * @param message
     * @param result
     */
    public static  void succeed(String message,Object result)
    {
        ResultBean bean = new ResultBean(0,message,result);
        ResponseUtil.printl(WebLocal.getResponse(),JSONObject.toJSON(bean).toString(),"json" );

    }

    /**
     * 出错了
     * @param message
     */
    public static  void fault(String message)
    {
        ResultBean bean = new ResultBean(-1,message,message);
        ResponseUtil.printl(WebLocal.getResponse(),JSONObject.toJSON(bean).toString(),"json" );
    }




}

class ResultBean
{
    /**
     * 0 成功
     * 1 失败
     */
    int code =0;

    /**
     * 返回消息
     */
    String message = null;

    /**
     * 返回数据
     */
    Object result = null;

    /**
     *
     * @param code -1 失败消息状态 0成功消息状态
     * @param message  消息说明
     * @param result 消息数据
     */
    public ResultBean(int code,String message,Object result)
    {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}